<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
 <link rel="stylesheet" href="../static/css/back/font.css">
 <link rel="stylesheet" href="../static/css/back/role.css">
    <link rel="stylesheet" href="../static/css/back/xadmin.css">
    <script type="text/javascript" src="../static/js/jquery-2.1.1.min.js"></script>
    
    <script type="text/javascript" src="../static/js/back/xadmin.js"></script>
     <script type="text/javascript" src="../static/js/back/activity-list.js"></script>
   
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
.manjian {
	float: left;
	text-align: center;
	line-height: 36px;
	margin: 3px;
}
.manjianhuodong{
	    margin-bottom: 60px;
}
.jjjj {
	    color: #fff;
    background-color: green;
    margin: 0 5px;
    /* width: 31px; */
    border: 1px #fff solid;
    display: block;
    width: 20px;
    float: right;
    text-align: -webkit-center;
    border-radius: 27px;
    font-size: 18px;
    font-weight: bold;
    margin-top: 8px;
    cursor: pointer;
}
.zhu-zhe{
margin: 10px 0 0 67px;
}
</style>
  </head>
  
  <body>
    <div class="x-body">
        <form action="" method="post" class="layui-form" lay-filter="add" onsubmit="javascript:return false;">
        		<input type="hidden" name="id" value="" id="paramKey" />
                <div class="layui-form-item hide" id="xin">
                    <label for="name" class="layui-form-label">
                        立减金额
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="li_xin"  required="" lay-verify=""
                        autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">元</div>
                </div>
                <div class="layui-form-item hide" id="zhe">
                    <label for="name" class="layui-form-label">
                        堂食折扣
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="room-zhe"  required="" lay-verify="" placeholder="请输入1-99区间的数字"
                        autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">%</div>
                    <div class="layui-inline zhu-zhe layui-word-aux"> 注：堂食折扣是指堂食订单付款时的折扣</div>
                    
                </div>
                <div class=" manjianhuodong  hide">
                <div class="layui-form-item " id="jian-out">
                    <label for="name" class="layui-form-label">
                        满减设置
                    </label>
                    <div class="layui-inline">
                       <span class="manjian"> 满</span> <input onkeydown="noClick(this)"  type="text" id="man1" name="man"  required="" style="width: 50px" lay-verify="number|required"
                        autocomplete="off" class="layui-input manjian"><span class="manjian"> 元</span> 
                       <span class="manjian"> 减</span><input  onkeydown="noClick(this)"  type="text" id="jian1" name="jian" required="" style="width: 50px" lay-verify="number|required"
                        autocomplete="off" class="layui-input manjian"><span class="manjian"> 元</span> 
                        <span class="jjjj" onclick="jiayihang()">+</span>
                    </div>
                </div>
				</div>
				
				<div class="danpinzhekou hide">
					<div class="x-body">
					<button class="layui-btn" onclick="addGoodsZhe()">添加菜品</button>
					      		<div class="layui-form-item">
									      <table class="layui-table">
									        <thead>
									          <tr>
									            <th>菜品名称</th>
									            <th>原价</th>
									            <th>折扣价</th>
									            <th>每单限购</th>
<!-- 									            <th>活动同享</th> -->
									            <th>操作</th>
									        </thead>
									        <tbody>
									        </tbody>
									      </table>
									      <div class="layui-form-mid layui-word-aux no-more-data hide">暂无更多数据</div>
									      <div class="page mypage" ></div> 
							      	</div>
					      </div>
					      <span style="    position: absolute; bottom: 100px; color: #999; left: 50px;">注: 多规格商品不能参加单品折扣活动</span>
					</div>
				
				<div class="adddanpinzhekou hide">
					<div class="chooseGoods">
						<div class="layui-form-item">
					      <label class="layui-form-label">分类</label>
					      <div class="layui-input-inline" >
					        <select class="goodsTypes" name="pId" lay-verify="" lay-filter="gts" lay-search="">
					          <option value="">无</option>
					        </select>
					      </div>
					   </div>
					   <div class="layui-form-item">
					      <label class="layui-form-label">商品</label>
					      <div class="layui-input-inline" lay-filter="gts3">
					        <select class="goodssel" name="p" lay-verify="" lay-filter="gts2" lay-search="">
					          <option value="">请选择</option>
					        </select>
					      </div>
					   </div>
				   </div>
				   <div class="layui-form-item">
				      <label class="layui-form-label">原价</label>
				      <div class="layui-inline">
				         <div class="layui-form-mid layui-word-aux zhekoujiapr">12.88</div>
				      </div>
				   </div>
				   <div class="layui-form-item">
				      <label class="layui-form-label">折扣价</label>
				      <div class="layui-input-inline">
				         <input  type="text" id="zhekoujia" name="" required=""  lay-verify=""
                        autocomplete="off" class="layui-input manjian">
				      </div>
				      <div class="layui-form-mid layui-word-aux">元</div>
				   </div>
				   <div class="layui-form-item">
				      <label class="layui-form-label">每单限购</label>
				      <div class="layui-input-inline">
				         <input  type="text" id="meidanxg" name="" required=""  lay-verify=""
                        autocomplete="off" class="layui-input manjian">
				      </div>
				      <div class="layui-form-mid layui-word-aux">份</div>
				   </div>
				   <!-- <div class="layui-form-item">
					    <label class="layui-form-label">是否和其他优惠活动叠加享受</label>
					    <div class="layui-input-block">
					      <input type="radio" name="status" value="1" checked="" title="是"  lay-filter='stat'>
					      <input type="radio" name="status" value="2" title="否" lay-filter='stat'>
					    </div>
				  </div> -->
				   
				      <div class="layui-form-item ">
				       		 <label class="layui-form-label"></label>
		               		 <button class="layui-btn addgoods" onclick="okbtn2()">确定</button>
		               		 <button class="layui-btn editgoods hide" onclick="okbtn3()">保存</button>
		               		 <button class="layui-btn" onclick="addGoodsZhe2()">取消</button>
		              	</div>
				</div>
			<!-- <div class="layui-form-item">
			      <label class="layui-form-label">上级菜单</label>
			      <div class="layui-input-inline">
			        <select class="pIdsel" name="pId" lay-verify="" lay-search="">
			          <option value="">无</option>
			        </select>
			      </div>
		   </div>
		   <div class="layui-form-item">
				<label class="layui-form-label">icon</label>
				<div class="layui-input-inline">
					<input type="tel" name="icon" lay-verify=""
						autocomplete="off" class="layui-input">
				</div>
			</div>
		   <div class="layui-form-item">
				<label class="layui-form-label">请求路径</label>
				<div class="layui-input-inline">
					<input type="tel" name="url" lay-verify=""
						autocomplete="off" class="layui-input">
				</div>
			</div>
		   <div class="layui-form-item">
				<label class="layui-form-label">排序</label>
				<div class="layui-input-inline">
					<input type="number" name="sort" lay-verify=""
						autocomplete="off" class="layui-input">
				</div>
			</div>
			 <div class="layui-form-item">
			    <label class="layui-form-label">是否显示</label>
			    <div class="layui-input-block">
			      <input type="checkbox" checked="" name="isShow" lay-skin="switch" lay-filter="switchShow" lay-text="是|否">
			    </div>
			  </div> -->
		   
		   
			    <div class="layui-form-item add_bot_btn">
               		 <button class="layui-btn" onclick="okbtn()">确定</button>
               		 <button class="layui-btn" onclick="x_admin_close()">取消</button>
              	</div>
            </form>
    </div>
    
    <script type="text/javascript">
	    	var _type ;
	    $(function(){
	    	_type= getUrlParam("actType");
	    	console.log(_type);
	    	if(_type == 1){
	    		$("#xin").show();
	    	}else if(_type == 2 || _type == 4 ){
	    		$(".manjianhuodong").show();
	    	}else if(_type==5){
	    		$("#zhe").show();
	    	}else if(_type==3){
	    		getTypeList();
	    		showGoodsList();
	    		//$(".add_bot_btn").hide();
	    		$(".danpinzhekou").show();
	    	}
	    	if(getUrlParam("type") == 'edit'){
	    		getInfo(_type);
	    	}
	    })
	    
	    var data = {};
	    function okbtn(){
	    	console.log(213456);
	    	if(_type==1){
	    		data['content'] = ($("#li_xin").val() *100).toFixed(0);
	    		data['activityTypeObj'] = "1" ;
	    		data['activityType'] = "1" ;
	    	}else if(_type==2 || _type == 4){
	    		var mbStr = "";
	    		var mn = $("input[name='man']");
	    		var ja = $("input[name='jian']");
	    		for (var i = 0; i < mn.length; i++) {
	    			var m = mn[i];
	    			var j = ja[i];
	    			mbStr += ($(m).val()*100).toFixed(0) + "-"+ ($(j).val()*100).toFixed(0) ;
	    			if((i+1) != mn.length){
	    				mbStr += ",";
	    			}
					console.log($(m).val()+"-"+$(j).val());
				}
				console.log(mbStr);
				data['content'] = mbStr;
				if(_type==4){
					data['activityTypeObj'] = "2" ;
				}else{
					data['activityTypeObj'] = "1" ;
				}
	    		data['activityType'] = _type ;
	    	}else if(_type==3){
	    		parent.getList();
	        	x_admin_close();
	    		return;
	    	}else if(_type==5){
	    		data['activityTypeObj'] = "2" ;
	    		data['activityType'] = _type ;
	    		data['content'] = $("#room-zhe").val()
	    	}
	    	updateInfo(data);
	    }
	    
	    function getInfo(tye){
	    	console.log(tye);
	    	_ajax_post('../act/getActivityList',{shopId:spid,activityType:tye},function(res){
	    		console.log(res.returnObject);
	    		if(! res.returnObject){
	    			$('.no-more-data').show();
	    			return;	
	    		}else{
	    			$('.no-more-data').hide();
	    		}
	    		if(tye == 1 ){
	    			$("#li_xin").val((res.returnObject[0].content / 100 ).toFixed(2));
	    		}else if(tye == 2 || tye == 4){
	    			var con = res.returnObject[0].content;
	    			var cons = con.split(',');
	    			for (var i = 0; i < cons.length; i++) {
	    				var conss = cons[i];
	    				console.log(conss);
						if(i==0){
							$("input[name='man']").val(((conss.split('-')[0])/100).toFixed(2));
							$("input[name='jian']").val(((conss.split('-')[1])/100).toFixed(2));
						}else{
							var html = '<div class="layui-form-item" id="jian-out">'
							      +'        <label for="name" class="layui-form-label"></label>                                                                                  '
							      +'    <div class="layui-inline">                                                                                                               '
							      +'       <span class="manjian"> 满</span> <input onkeydown="noClick(this)"  type="text" id="man2" name="man" value="'+((conss.split('-')[0])/100).toFixed(2)+'"  required="" style="width: 50px" lay-verify="number|required"'
							      +'        autocomplete="off" class="layui-input manjian"><span class="manjian"> 元</span>                                                      '
							      +'       <span class="manjian"> 减</span><input onkeydown="noClick(this)"   type="text" id="jian2" name="jian" required="" value="'+((conss.split('-')[1])/100).toFixed(2)+'" style="width: 50px" lay-verify="number|required"'
							      +'        autocomplete="off" class="layui-input manjian"><span class="manjian"> 元</span>                                                      '
							      +'        <span class="jjjj" onclick="jianyihang(this)">-</span><span class="jjjj" onclick="jiayihang()">+</span>                                  '
							      +'    </div>                                                                                                                                   '
							      +'</div>';                                                                                                                                     
					    	$(".manjianhuodong").append(html);
						}
					}
	    		}else if(tye == 3){
	    			
	    		}else if(tye == 5){
	    			$("#li_xin").val(res.returnObject[0].content);
	    		}
	    	})
	    	
	    }
	    
	    function jiayihang(){
	    	var html = '<div class="layui-form-item" id="jian-out">'
			      +'        <label for="name" class="layui-form-label"></label>                                                                                  '
			      +'    <div class="layui-inline">                                                                                                               '
			      +'       <span class="manjian"> 满</span> <input onkeydown="noClick(this)"  type="text" id="man2" name="man"  required="" style="width: 50px" lay-verify="number|required"'
			      +'        autocomplete="off" class="layui-input manjian"><span class="manjian"> 元</span>                                                      '
			      +'       <span class="manjian"> 减</span><input  onkeydown="noClick(this)"  type="text" id="jian2" name="jian" required="" style="width: 50px" lay-verify="number|required"'
			      +'        autocomplete="off" class="layui-input manjian"><span class="manjian"> 元</span>                                                      '
			      +'        <span class="jjjj" onclick="jianyihang(this)">-</span><span class="jjjj"  onclick="jiayihang()">+</span>                                  '
			      +'    </div>                                                                                                                                   '
			      +'</div>';                                                                                                                                     
	    	$(".manjianhuodong").append(html);
	    }
	    function noClick(e){
	    	console.log(e);
	    	 let theEvent = window.event || e;
		        let code = theEvent.keyCode || theEvent.which;
		        if (code == 13) {
		            return false; //这里写你回车按下后你想触发的那个按钮的id是多少
		        }
	    }
	    function jianyihang(obj){
	    	console.log(obj);
	    	$(obj).parent().parent().remove();
	    }
    </script>
    
    <script>
    _ddd = null;
    var form = null;
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
         form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });
         // 
          form.on('select(gts)', function(data){
        	  console.log(data.value);
        	  if(data.value){
	        	 // showGoodsList();
// 	        	  console.log(tid);
// 	          	var html ='<option value="">请选择</option><option value="xptv">米饭</option><option value="26o07">1</option><option value="7c">大米饭</option><option value="b8qx">又是大米饭</option><option value="mhai">大米</option><option value="xpu3">大大米</option>';
	          	var html ='<option value="">请选择</option>';
	          	$(".goodssel").html(html);
	          	form.render();
// 	          	$(".goodssel").html(html);
	          	_ajax_post('../goods/getGoodsList',{pageSize:100,goodsTypeId:data.value,shopId:spid},function(res){
	          		console.log(res);
	          	  var list =  res.returnObject;
	          	  html = '';
	         		  $.each(list.list,function(i,v,arr){
	         			  console.log(v.goodsTitle);
	             			 html='<option  value="'+v.id+'-'+v.priceOut+'">'+v.goodsTitle+'</option>';
				          	$(".goodssel").append(html);
				          	form.render();
	         		  })
	          	})
	          	
// 	             			$(".goodssel").append(html);
        	  }else{
        		  
        	  }
        	});  
          form.on('select(gts2)', function(data){
        	 console.log(data);
        	 $('.zhekoujiapr').text(((data.value.split('-')[1])/100).toFixed(2));
        	 
          })
          //监听提交
          form.on('submit(add)', function(data){
        	  
        	  if(data.field.isShow == "on") {
                  data.field.isShow = "1";
              } else {
                  data.field.isShow = "0";
              }
            console.log(data.field);
            updateRule(data.field);
            return false;
          });
          
          form.val("formAdd", _ddd);
          
          
          
        });
    </script>
    <script type="text/javascript">
   
    
    //单品折扣
    function getTypeList(){
	  _ajax_post_token('../goods/getGoodsTypeList',{pageSize:100,shopId:spid},function(res){
		  var list =  res.returnObject;
		  var html = '<option value="">请选择</option>';
		  $.each(list.list,function(i,v,arr){
    		  if(list){
    			 html+='<option value="'+v.id+'">'+v.title+'</option>';
    		  }
		  })
		  $(".goodsTypes").html(html);
		  form.render();
		  
	  })
  }
    
    function addGoodsZhe(){
    	$(".adddanpinzhekou").show();
    	$(".danpinzhekou").hide();
    	$(".chooseGoods").show();
    	$(".addgoods").show();
    	$(".editgoods").hide();
    	$('.add_bot_btn').hide();
    }
    function addGoodsZhe2(){
    	$(".adddanpinzhekou").hide();
    	$(".danpinzhekou").show();
    	$(".chooseGoods").hide();
    	$(".addgoods").hide();
    	$(".editgoods").hide();
    	$('.add_bot_btn').show();
    }
    function showGoodsList(){
    	_ajax_post_token('../act/getActivityDisList',{pageSize:100,shopId:spid},function(res){
    		console.log(res);
    		if(!res.returnObject){
    			return;
    		}
    		var html="";
    		$.each(res.returnObject.list,function(i,v,arr){
    			console.log(v);
  			  html+=' <tr><td>'
      	             +v.goodsTitleB
      	             +'</td>                                                                                           '
      	             +' <td>'+(v.goodsPriceOut/100).toFixed(2)+'</td>                                                                                                      '
      	             +' <td>'+(v.goodsPriceDis/100).toFixed(2)+'</td>                                                                                                      '
//       	             +' <td>'+v.goodsStock+'</td>                                                                                                      '
      	             +' <td>'+v.forNum+'</td>                                                                                                      '
//       	             +' <td>'+(v.status==1?"是":"否")+'</td>                                                                                                      '
      	             +' <td class="td-manage">    '
      	             +'   <a title="编辑"  onclick="editDis(\''+v.id+'\')" href="javascript:;">                       '
      	             +'     <i class="iconfont icon-edit"></i>                                                                                 '
      	             +'   </a>'
      	             + '<a title="删除" onclick="member_del(\''+v.id+'\')" href="javascript:;">                                         '
      	             +'     <i class="iconfont icon-delete x-red"></i>                                                                                 '
      	             +'   </a>  </td> '
      	             +'</tr>';
  		  })
  		  $(".layui-table tbody").html(html);
    		form.render();
  	  })
		  
    }
    var _editId = "";
    function editDis(id){
    	console.log(id);
    	_editId = id;
    	$(".adddanpinzhekou").show();
    	$(".danpinzhekou").hide();
    	$(".chooseGoods").hide();
    	$(".addgoods").hide();
    	$(".editgoods").show();
    	
    	_ajax_post_token('../act/getActivityDisList',{id:id,shopId:spid},function(res){
    		console.log(res);
    		var vv =res.returnObject.list[0];
    		console.log(vv);
    		$("#zhekoujia").val((vv.goodsPriceDis/100).toFixed(2)) ;
//         	$("input[name='status'][value='" + vv.status + "']").prop("checked", "checked");

	    	form.val('add',{'status':vv.status});
    	    $("#meidanxg").val(vv.forNum);
    	})
    }
    function okbtn2(){
    	var _data = {};
    	_data['goodsId'] = $('.goodssel').val().split('-')[0];
    	_data['goodsPriceOut'] = ($('.goodssel').val().split('-')[1]);
    	_data['activityId'] = spid;
    	_data['goodsPriceDis'] = $("#zhekoujia").val() * 100;
    	_data['status']= $("input[name='status']:checked").val();
    	_data['forNum']= $("#meidanxg").val();
    	_ajax_post_token('../act/addActivityDisInfo.do',_data,function(res){
    		console.log(res);
    		showGoodsList();
    		addGoodsZhe2();
  	  })
    }
    function okbtn3(){
    	var _data = {};
    	_data['activityId'] = spid;
    	_data['goodsPriceDis'] = $("#zhekoujia").val() * 100;
    	_data['status']= $("input[name='status']:checked").val();
	    _data['forNum']= $("#meidanxg").val();
	    _data['id'] = _editId;
    	_ajax_post_token('../act/editActivityDisInfo.do',_data,function(res){
    		console.log(res);
    		showGoodsList();
    		addGoodsZhe2();
  	  })
    }
    function member_del(id){
    	_ajax_post_token('../act/editActivityDisInfo.do',{status:0,id:id},function(res){
    		console.log(res);
    		addGoodsZhe2();
    		showGoodsList();
  	  })
    }
    </script>

  </body>

</html>